﻿using System;
using System.Data;
using System.Text;
using System.Collections.Generic;
using System.Data.OracleClient;
namespace GSLMS.DAL.Oracle
{
	/// <summary>
	/// 数据访问类:COL_CHECKINFO
	/// </summary>
	public partial class COL_CHECKINFO : BaseDAL<GSLMS.Entity.TB_COL_CHECKINFO>
	{
		private readonly GSLMS.Core.Loger log = new Core.Loger();
		public COL_CHECKINFO()
		{}
		#region  Method
		/// <summary>
		///  增加一条数据
		/// </summary>
		public override bool Add(GSLMS.Entity.TB_COL_CHECKINFO model)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", model.ID),
								new OracleParameter("P_LOANID", model.LOANID),
								new OracleParameter("P_PROID", model.PROID),
								new OracleParameter("P_CONID", model.CONID),
								new OracleParameter("P_LEFTAMT", model.LEFTAMT),
								new OracleParameter("P_CHECKMOD", model.CHECKMOD),
								new OracleParameter("P_CHECKBY1", model.CHECKBY1),
								new OracleParameter("P_CHECKBY2", model.CHECKBY2),
								new OracleParameter("P_STARTDATE", model.STARTDATE),
								new OracleParameter("P_ENDDATE", model.ENDDATE),
								new OracleParameter("P_CREATEDATE", model.CREATEDATE),
								new OracleParameter("P_RISKLEVEL", model.RISKLEVEL),
								new OracleParameter("P_CHECKCONTENT", model.CHECKCONTENT),
								new OracleParameter("P_LOANFOR", model.LOANFOR),
								new OracleParameter("P_PAYSOURCE", model.PAYSOURCE),
								new OracleParameter("P_CUSTBUSS", model.CUSTBUSS),
								new OracleParameter("P_CUSTMANAGE", model.CUSTMANAGE),
								new OracleParameter("P_CUSTFIN", model.CUSTFIN),
								new OracleParameter("P_ASSURE", model.ASSURE),
								new OracleParameter("P_PLEDGE", model.PLEDGE),
								new OracleParameter("P_OTHERINFO", model.OTHERINFO),
								new OracleParameter("P_STATUS", model.STATUS),
								new OracleParameter("P_CONFIRMBY", model.CONFIRMBY),
								new OracleParameter("P_CONFIRMDATE", model.CONFIRMDATE)};
  
			for (int i = 0; i < 24; i++)
			{
				parms[i].Direction = ParameterDirection.Input;
			}

			try
			{
				OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_col_checkinfo_add", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///  更新一条数据
		/// </summary>
		public override bool Update(GSLMS.Entity.TB_COL_CHECKINFO model)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", model.ID),
								new OracleParameter("P_LOANID", model.LOANID),
								new OracleParameter("P_PROID", model.PROID),
								new OracleParameter("P_CONID", model.CONID),
								new OracleParameter("P_LEFTAMT", model.LEFTAMT),
								new OracleParameter("P_CHECKMOD", model.CHECKMOD),
								new OracleParameter("P_CHECKBY1", model.CHECKBY1),
								new OracleParameter("P_CHECKBY2", model.CHECKBY2),
								new OracleParameter("P_STARTDATE", model.STARTDATE),
								new OracleParameter("P_ENDDATE", model.ENDDATE),
								new OracleParameter("P_CREATEDATE", model.CREATEDATE),
								new OracleParameter("P_RISKLEVEL", model.RISKLEVEL),
								new OracleParameter("P_CHECKCONTENT", model.CHECKCONTENT),
								new OracleParameter("P_LOANFOR", model.LOANFOR),
								new OracleParameter("P_PAYSOURCE", model.PAYSOURCE),
								new OracleParameter("P_CUSTBUSS", model.CUSTBUSS),
								new OracleParameter("P_CUSTMANAGE", model.CUSTMANAGE),
								new OracleParameter("P_CUSTFIN", model.CUSTFIN),
								new OracleParameter("P_ASSURE", model.ASSURE),
								new OracleParameter("P_PLEDGE", model.PLEDGE),
								new OracleParameter("P_OTHERINFO", model.OTHERINFO),
								new OracleParameter("P_STATUS", model.STATUS),
								new OracleParameter("P_CONFIRMBY", model.CONFIRMBY),
								new OracleParameter("P_CONFIRMDATE", model.CONFIRMDATE)};
  
			for (int i = 0; i < 24; i++)
			{
				parms[i].Direction = ParameterDirection.Input;
			}

			try
			{
				OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_col_checkinfo_update", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///  删除一条数据
		/// </summary>
		public override bool Delete(long ID)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", ID)};
  
				parms[0].Direction = ParameterDirection.Input;

			try
			{
				OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_col_checkinfo_delete", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///DataRowToModel 
		/// </summary>
		private GSLMS.Entity.TB_COL_CHECKINFO DataRowToModel(DataRow dr)
		{
			if (dr != null && dr.ItemArray.Length > 0)
			{
				GSLMS.Entity.TB_COL_CHECKINFO model = new GSLMS.Entity.TB_COL_CHECKINFO();
				if(dr["ID"]!=null && dr["ID"].ToString()!="")
				{
					model.ID=OracleHelper.ToLong(dr["ID"].ToString());
				}
				if(dr["LOANID"]!=null && dr["LOANID"].ToString()!="")
				{
					model.LOANID=OracleHelper.ToLong(dr["LOANID"].ToString());
				}
				if(dr["PROID"]!=null && dr["PROID"].ToString()!="")
				{
					model.PROID=OracleHelper.ToLong(dr["PROID"].ToString());
				}
				if(dr["CONID"]!=null && dr["CONID"].ToString()!="")
				{
					model.CONID=OracleHelper.ToLong(dr["CONID"].ToString());
				}
				if(dr["LEFTAMT"]!=null && dr["LEFTAMT"].ToString()!="")
				{
					model.LEFTAMT=OracleHelper.ToDecimal(dr["LEFTAMT"].ToString());
				}
				if(dr["CHECKMOD"]!=null && dr["CHECKMOD"].ToString()!="")
				{
					model.CHECKMOD=dr["CHECKMOD"].ToString();
				}
				if(dr["CHECKBY1"]!=null && dr["CHECKBY1"].ToString()!="")
				{
					model.CHECKBY1=dr["CHECKBY1"].ToString();
				}
				if(dr["CHECKBY2"]!=null && dr["CHECKBY2"].ToString()!="")
				{
					model.CHECKBY2=dr["CHECKBY2"].ToString();
				}
				if(dr["STARTDATE"]!=null && dr["STARTDATE"].ToString()!="")
				{
					model.STARTDATE=DateTime.Parse(dr["STARTDATE"].ToString());
				}
				if(dr["ENDDATE"]!=null && dr["ENDDATE"].ToString()!="")
				{
					model.ENDDATE=DateTime.Parse(dr["ENDDATE"].ToString());
				}
				if(dr["CREATEDATE"]!=null && dr["CREATEDATE"].ToString()!="")
				{
					model.CREATEDATE=DateTime.Parse(dr["CREATEDATE"].ToString());
				}
				if(dr["RISKLEVEL"]!=null && dr["RISKLEVEL"].ToString()!="")
				{
					model.RISKLEVEL=dr["RISKLEVEL"].ToString();
				}
				if(dr["CHECKCONTENT"]!=null && dr["CHECKCONTENT"].ToString()!="")
				{
					model.CHECKCONTENT=dr["CHECKCONTENT"].ToString();
				}
				if(dr["LOANFOR"]!=null && dr["LOANFOR"].ToString()!="")
				{
					model.LOANFOR=dr["LOANFOR"].ToString();
				}
				if(dr["PAYSOURCE"]!=null && dr["PAYSOURCE"].ToString()!="")
				{
					model.PAYSOURCE=dr["PAYSOURCE"].ToString();
				}
				if(dr["CUSTBUSS"]!=null && dr["CUSTBUSS"].ToString()!="")
				{
					model.CUSTBUSS=dr["CUSTBUSS"].ToString();
				}
				if(dr["CUSTMANAGE"]!=null && dr["CUSTMANAGE"].ToString()!="")
				{
					model.CUSTMANAGE=dr["CUSTMANAGE"].ToString();
				}
				if(dr["CUSTFIN"]!=null && dr["CUSTFIN"].ToString()!="")
				{
					model.CUSTFIN=dr["CUSTFIN"].ToString();
				}
				if(dr["ASSURE"]!=null && dr["ASSURE"].ToString()!="")
				{
					model.ASSURE=dr["ASSURE"].ToString();
				}
				if(dr["PLEDGE"]!=null && dr["PLEDGE"].ToString()!="")
				{
					model.PLEDGE=dr["PLEDGE"].ToString();
				}
				if(dr["OTHERINFO"]!=null && dr["OTHERINFO"].ToString()!="")
				{
					model.OTHERINFO=dr["OTHERINFO"].ToString();
				}
				if(dr["STATUS"]!=null && dr["STATUS"].ToString()!="")
				{
                    model.STATUS = OracleHelper.ToInt(dr["STATUS"].ToString());
				}
				if(dr["CONFIRMBY"]!=null && dr["CONFIRMBY"].ToString()!="")
				{
					model.CONFIRMBY=dr["CONFIRMBY"].ToString();
				}
				if(dr["CONFIRMDATE"]!=null && dr["CONFIRMDATE"].ToString()!="")
				{
					model.CONFIRMDATE=DateTime.Parse(dr["CONFIRMDATE"].ToString());
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public override GSLMS.Entity.TB_COL_CHECKINFO GetByID(long ID)
		{
			GSLMS.Entity.TB_COL_CHECKINFO sModel = new GSLMS.Entity.TB_COL_CHECKINFO();
			string sql = "";
			sql = "select * from TB_COL_CHECKINFO where id=" + ID.ToString();
			DataSet ds = OracleHelper.ExecuteDataset(sql);
			if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
			{
				sModel = DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
			return null;
			}
			return sModel;
		}

		/// <summary>
		/// 分页提取数据
		/// </summary>
		public override List<GSLMS.Entity.TB_COL_CHECKINFO> GetList(GSLMS.Entity.TB_COL_CHECKINFO searchParam)
		{
			var list=new List<GSLMS.Entity.TB_COL_CHECKINFO>();
			DataTable dt = null;
			string tblName = "TB_COL_CHECKINFO";
			string sqlWhere="";
			string strSort="";
			int pageSize=20;
			int pageIndex=1;
			string strFields="*";
			int totalCount = 0;
			int countFlag = 1;
			dt = OracleHelper.GetPageData(tblName, strFields, strSort, pageSize, pageIndex,countFlag, sqlWhere, out totalCount);
			if (dt != null && dt.Rows.Count > 0)
			{
				for (int i = 0; i < dt.Rows.Count; i++)
				{
					GSLMS.Entity.TB_COL_CHECKINFO model = new GSLMS.Entity.TB_COL_CHECKINFO();
					model = DataRowToModel(dt.Rows[i]);
					list.Add(model);
				}
			}
			else
			{
				return null;
			}
			return list;
		}

		#endregion  Method
	}
}

